package com.sunmnet.auto.spring.mvc;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

public class Main {
	
	private final static int DB = 1;
	
	private final static int PDM = 2;
	
	/** LOG  */
	private final static org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(Main.class);
	
	/**
	 * 启动方法
	 *
	 * @param args
	 * @throws IOException 
	 * @throws SQLException 
	 */
	public static void main(String[] args) {
		
		ASMConfig conf = ASMConfig.getInstance();
		
		if (DB == conf.getDoType()) {
			LOG.info("从数据库生成文件");
			Connection conn = null;
			try {
				conn = com.sunmnet.pub.db.DB.getConnection(ASMConfig.DS);
				AutoSpringMVC.getBeanFromDB(
						conn, 
						conf.getTableArray(), 
						conf.getTablePreArray());
			} catch (Exception e) {
				LOG.error("获取数据库连接异常", e);
			}
			
		} else if (PDM == conf.getDoType()) {
			LOG.info("从PDM生成文件");
			try {
//				AutoSpringMVC.getTBStructuresFromPDM(conf.getPdmPath(), conf.getTableArray(), conf.getTablePreArray());
				AutoSpringMVC.getBeanFromPDM(conf.getPdmPath(), conf.getTableArray(), conf.getTablePreArray());
			} catch (Exception e) {
				LOG.error("从PDM生成文件  -- 失败!", e);
			}
			LOG.info("从PDM生成文件-- 成功!");
		}
	}

}
